package com.weitu.environmental.monitor.controller;


import com.weitu.base.controller.BaseController;
import com.weitu.environmental.monitor.entity.MonitorPoint;
import com.weitu.environmental.monitor.entity.MonitorPointAndProject;
import com.weitu.environmental.monitor.service.MonitorPointAndProjectService;
import com.weitu.paging.DataGridPagination;
import com.weitu.plugin.PageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangqingxi 2017-03-31
 */
@Controller
@RequestMapping("environmental/monitor/pointAndProject")
public class MonitorPointAndProjectController extends BaseController {

    private static final String MODULE_BATH_PATH = BASE_JSP_PATH + "environmental/monitor/pointAndProject";

    private final MonitorPointAndProjectService monitorPointAndProjectService;

    @Autowired
    public MonitorPointAndProjectController(MonitorPointAndProjectService monitorPointAndProjectService) {
        this.monitorPointAndProjectService = monitorPointAndProjectService;
    }






    @ResponseBody
    @RequestMapping("/findByParam")
    public Object findByParam(HttpServletRequest request) {


        Map<String, Object> paramMap = new HashMap<String, Object>();

        //获取前台参数
        putParametersIntoMap(paramMap);

        Integer totalNum = monitorPointAndProjectService.findByParamCount(paramMap);//获取总数
        DataGridPagination pagination = DataGridPagination.getInstance(request, totalNum);

        PageView pageView = pagination.getPageView();//生成pageView分页对象
        paramMap.put("pageView", pageView);

        List<MonitorPointAndProject> monitorPointAndProjects = monitorPointAndProjectService.findByParam(paramMap);

        return pagination.flushDataGridData(monitorPointAndProjects);
    }

    @ResponseBody
    @RequestMapping("/findByPointId")
    public List<MonitorPointAndProject> findByPointId(String pointId){
        return monitorPointAndProjectService.findByPointId(pointId);
    }
    @ResponseBody
    @RequestMapping("/findDropDownListByPointId")
    public List<Map> findDropDownListByPointId(String pointId){
        return monitorPointAndProjectService.findDropDownListByPointId(pointId);
    }






}
